Move xcsv badchars to QString.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 29 Sep 2014 02:53:05 +0000 (02:53 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 29 Sep 2014 02:53:05 +0000 (02:53 +0000)
gpsbabel/csv_util.cc
gpsbabel/csv_util.h
gpsbabel/xcsv.cc

index b71d9ec45d52a89412a1cb7abcc71f070524883d..9915f9b6e2b36994213b2b218095a4e41afba1e0 100644 (file)
@@ -727,7 +727,7 @@ void xcsv_file_init(void)
   xcsv_file.field_delimiter = QString();
   xcsv_file.field_encloser = QString();
   xcsv_file.record_delimiter = QString();
-  xcsv_file.badchars = NULL;
+  xcsv_file.badchars = QString();
   xcsv_file.ifield_ct = 0;
   xcsv_file.ofield_ct = 0;
   xcsv_file.xcsvfp = NULL;
index 533f918592d6cd923f02876ba0edc8ef7968f11d..c6440827e05990dd31b895decc2e13a3b1dc4235 100644 (file)
@@ -124,7 +124,7 @@ class XcsvFile {
   QString field_encloser;      /* doublequote, etc... */
   QString record_delimiter;    /* newline, c/r, etc... */
 
-  char*  badchars;             /* characters we never write to output */
+  QString badchars;            /* characters we never write to output */
 
   queue ifield;                /* input field mapping */
   queue* ofield;               /* output field mapping */
index da3e516c497e0d7bb9ff052e9a492ee49128be8b..a50c176b129fa34d129fa54a44bc8ab91bfc0519 100644 (file)
@@ -180,10 +180,7 @@ xcsv_destroy_style(void)
   xcsv_file.field_delimiter = QString();
   xcsv_file.field_encloser = QString();
   xcsv_file.record_delimiter = QString();
-
-  if (xcsv_file.badchars) {
-    xfree(xcsv_file.badchars);
-  }
+  xcsv_file.badchars = QString();
 
   if (xcsv_file.description) {
     xfree(xcsv_file.description);
@@ -244,7 +241,7 @@ xcsv_parse_style_line(char* sbuff)
       sp = csv_stringtrim(&sbuff[16], "\"", 1);
       cp = xcsv_get_char_from_constant_table(sp);
       if (cp) {
-        xcsv_file.field_delimiter = xstrdup(cp);
+        xcsv_file.field_delimiter = cp;
         xfree(sp);
       } else {
         xcsv_file.field_delimiter = sp;
@@ -254,15 +251,10 @@ xcsv_parse_style_line(char* sbuff)
 
       /* field delimiters are always bad characters */
       if (0 == strcmp(p, "\\w")) {
-        char* s = xstrappend(xcsv_file.badchars, " \n\r");
-        if (xcsv_file.badchars) {
-          xfree(xcsv_file.badchars);
-        }
-        xcsv_file.badchars = s;
+        xcsv_file.badchars = " \n\r";
       } else {
-        xcsv_file.badchars = xstrappend(xcsv_file.badchars, p);
+        xcsv_file.badchars += p;
       }
-
       xfree(p);
 
     } else
@@ -271,52 +263,30 @@ xcsv_parse_style_line(char* sbuff)
         sp = csv_stringtrim(&sbuff[15], "\"", 1);
         cp = xcsv_get_char_from_constant_table(sp);
         if (cp) {
-          xcsv_file.field_encloser = xstrdup(cp);
+          xcsv_file.field_encloser = cp;
           xfree(sp);
         } else {
           xcsv_file.field_encloser = sp;
         }
 
         p = csv_stringtrim(CSTR(xcsv_file.field_encloser), " ", 0);
-
-        /* field_enclosers are always bad characters */
-        if (xcsv_file.badchars) {
-          xcsv_file.badchars = (char*) xrealloc(xcsv_file.badchars,
-                                                strlen(xcsv_file.badchars) +
-                                                strlen(p) + 1);
-        } else {
-          xcsv_file.badchars = (char*) xcalloc(strlen(p) + 1, 1);
-        }
-
-        strcat(xcsv_file.badchars, p);
-
+        xcsv_file.badchars += p;
         xfree(p);
-
       } else
 
         if (ISSTOKEN(sbuff, "RECORD_DELIMITER")) {
           sp = csv_stringtrim(&sbuff[17], "\"", 1);
           cp = xcsv_get_char_from_constant_table(sp);
           if (cp) {
-            xcsv_file.record_delimiter = xstrdup(cp);
+            xcsv_file.record_delimiter = cp;
             xfree(sp);
           } else {
             xcsv_file.record_delimiter = sp;
           }
 
-          p = csv_stringtrim(CSTR(xcsv_file.record_delimiter), " ", 0);
-
           /* record delimiters are always bad characters */
-          if (xcsv_file.badchars) {
-            xcsv_file.badchars = (char*) xrealloc(xcsv_file.badchars,
-                                                  strlen(xcsv_file.badchars) +
-                                                  strlen(p) + 1);
-          } else {
-            xcsv_file.badchars = (char*) xcalloc(strlen(p) + 1, 1);
-          }
-
-          strcat(xcsv_file.badchars, p);
-
+          p = csv_stringtrim(CSTR(xcsv_file.record_delimiter), " ", 0);
+          xcsv_file.badchars += p;
           xfree(p);
 
         } else
@@ -365,17 +335,7 @@ xcsv_parse_style_line(char* sbuff)
                       } else {
                         p = sp;
                       }
-
-                      if (xcsv_file.badchars) {
-                        xcsv_file.badchars = (char*) xrealloc(xcsv_file.badchars,
-                                                              strlen(xcsv_file.badchars) +
-                                                              strlen(p) + 1);
-                      } else {
-                        xcsv_file.badchars = (char*) xcalloc(strlen(p) + 1, 1);
-                      }
-
-                      strcat(xcsv_file.badchars, p);
-
+                      xcsv_file.badchars += p;
                       xfree(p);
 
                     } else
@@ -663,7 +623,7 @@ xcsv_wr_init(const char* fname)
       setshort_mustuniq(xcsv_file.mkshort_handle, atoi(snuniqueopt));
     }
 
-    setshort_badchars(xcsv_file.mkshort_handle, xcsv_file.badchars);
+    setshort_badchars(xcsv_file.mkshort_handle, CSTR(xcsv_file.badchars));
 
   }
   xcsv_file.gps_datum = GPS_Lookup_Datum_Index(opt_datum);